<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="求职者名称" prop="dutyPerson">
        <el-input
          v-model="queryParams.dutyPerson"
          placeholder="请输入求职者"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQueryFn"
        />
      </el-form-item>
      <el-form-item label="推荐人名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入推荐人"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQueryFn"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryFn">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQueryFn">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAddFn"
          v-hasPermi="['pmp:recruit:add']"
        >新增简历</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDeleteFn"
          v-hasPermi="['pmp:recruit:remove']"
        >删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExportFn"
          v-hasPermi="['pmp:recruit:export']"
        >发送周报</el-button>
      </el-col> -->
    </el-row>

    <el-table v-loading="loading" :data="recruitList" @selection-change="handleSelectionChangeFn">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="求职者名称" prop="principalName" width="120" />
      <el-table-column label="推荐人" prop="principalName" width="120" />
      <el-table-column label="联系电话" prop="principalName" width="120" />
      <el-table-column label="技术类型" prop="workType" :show-overflow-tooltip="true" width="150">
        <template slot-scope="scope">
          <span>{{ ifWorkType(scope.row.workType) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="面试官" prop="projectName" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="推荐时间" prop="startTime" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="预约时间" align="startDate" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="inside" :show-overflow-tooltip="true" width="150">
        <template slot-scope="scope">
          <span>{{ isValue(scope.row.inside) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleScreenFn(scope.row)"
            v-hasPermi="['pmp:recruit:screen']"
          >筛选</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleOrderFn(scope.row)"
            v-hasPermi="['pmp:recruit:order']"
          >预约</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDownLondFn(scope.row)"
            v-hasPermi="['pmp:recruit:download']"
          >下载</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEvaluateFn(scope.row)"
            v-hasPermi="['pmp:recruit:evaluate']"
          >评价</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDecideFn(scope.row)"
            v-hasPermi="['pmp:recruit:decide']"
          >入职决定</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getListFn"
    />
    <!-- 流程页面 -->
    <circulation-detail ref='circulationDetail' :propFormData.sync="recruitData.formData" ></circulation-detail>
  </div>
</template>

<script>
  import { apiRequestListwait } from "@/api/pmp/api.recruit";

  import circulationDetail from './components/circulation.detail.vue';
  export default {
    name: "schedule",
    components: {
      circulationDetail
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 角色表格数据
        recruitList: [],
        // 详情页、修改页面数据
        recruitData: {
          title: "添加角色",
          formData: undefined
        },
        // 预约页面数据
        orderData: {},
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          roleName: undefined,
          roleKey: undefined,
          status: undefined
        },
        // 工时类型数据字典
        recruitStatus: [],

        defaultProps: {
          children: "children",
          label: "label"
        }
      };
    },
    computed: {
      isValue () {
        return (val)=> {
          return val?'是':'否';
        };
      },
      ifWorkType () {
        return (val)=> {
          return this.recruitStatus.find((item) => item.dictValue == val).dictLabel;
        };
      }
    },
    created() {
      this.getListFn();
      this.apiGetDicts("recruit_status").then(response => {
        this.recruitStatus = response.data;
      });
    },
    methods: {
      /** 查询角色列表 */
      getListFn() {
        this.loading = true;
        apiRequestListwait(this.queryParams).then(
          response => {
            this.recruitList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      /** 搜索按钮操作 */
      handleQueryFn() {
        this.queryParams.pageNum = 1;
        this.getListFn();
      },
      /** 重置按钮操作 */
      resetQueryFn() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQueryFn();
      },
      // 多选框选中数据
      handleSelectionChangeFn(selection) {
        this.ids = selection.map(item => item.recruitId);
        this.single = selection.length!=1;
        this.multiple = !selection.length;
      },
      /** 新增简历 */
      handleAddFn() {
        this.open = true;
        this.recruitData = {
          title: "添加角色",
          form: {}
        };
        this.$refs.recruitEdit.openDetail();
      },
      /** 筛选 */
      handleScreenFn(row) {
        let form = {};
        const recruitId = row.id;
        form = this.recruitList.find(item => item.recruitId == recruitId);
        form.workType = form.workType + "";
        form.timeData = [form.startTime, form.endTime];

        this.recruitData.title = "修改角色";
        this.recruitData.formData = form;
        this.$refs.recruitEdit.openDetail();

      },
      /** 预约 */
      handleOrderFn(row) {
        this.orderData.id = row.id;
        this.$refs.recruitDetail.openDetail();
      },
      /** 评价 */
      handleEvaluateFn(row) {

      },
      /** 决定入职 */
      handleDecideFn(row) {

      },
      /** 下载 */
      handleDownLondFn(row) {

      },
      /** 详情 */
      handleDetailFn(row) {

        this.$refs.orderDetail.openDetail();
      },
      /** 删除按钮操作 */
      handleDeleteFn(row) {
        const recruitIds = row.recruitId || this.ids;
        this.$confirm('是否确认删除编号为"' + recruitIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return apirecruitDel({recruitIds});
        }).then(() => {
          this.getListFn();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      }
    }
  };
</script>
